<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@ page import="java.util.*" %>
	<%@ page import="goods.*"%>
	<%@ page import="java.sql.Timestamp" %>

    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ include file="/Dmyna/admin/head.jsp" %>
<%!private static int count = 0001;%>

<%
	String optionColor[] = { "블렉", "화이트", "그레이", "카키", "핑크", "레드",
			"옐로우", "퍼플", "스카이" };
	String optionSize[] = { "FREE", "S", "M", "L", "XL", "XXL",
			"220mm", "230mm", "240mm", "260mm", "270mm" };

	String code = request.getParameter("gs_code");
	GoodsItem goodsItem = null;
	GoodsManager goodsManager = GoodsManager.getInstance();
	int gs_middle_code = goodsManager.select3("goods_info");
%>

<c:set var="goodsItem" value="<%=goodsItem%>" />
<script type="text/javascript">
function validate(form){
	
	var f = document.goods;
	
	var checked_color_items = 0;
	var checked_size_items = 0;
	var checked_image = 0;
	var checked_image2 = 0;
	
	for (var i = 0; i < f.elements.length; i++) //특정 영역을 체크 할때는 숫자로 대신 한다 예: for(i=3;i<21;i++)
	{
		if((f.elements[i].name == "color_code") && (f.elements[i].checked)) {
			checked_color_items++;
		}else if((f.elements[i].name == "size_code") && (f.elements[i].checked)) {
			checked_size_items++;
		}
	}
	if(f.gs_img.value.length > 0){
		checked_image++;
	}
	if(f.gs_img2.value.length > 0){
		checked_image2++;
	}
	
	//파일 유효성과 확장자 체크
/* 	var addfile = f.gs_img.length;
	var j = 0;
   	var k = 0;
   	for (var i=0;i<addfile;i++)
    {       
     	if (f.tb_image[i].value.length > 0){    
     		j = j + 1;
     	}
     	var text = f.tb_image[i].value.substring(f.tb_image[i].value.lastIndexOf(".") + 1);     
     	if (text == "jpg" || text == "jpeg" || text =="gif" || text == "JPG" || text == "JPEG" || text == "GIF"){
     		k = k + 1;
     	}
    }     
    if (j == 0){
     	alert("적어도 하나의 파일은 올리셔야 합니다.");
     	return false;
    }
    	if (k == 0){
     	alert("jpg,jpeg,gif 파일 이외에는 올릴수 없습니다.");
     	return false;
    } */

    oEditors.getById["gs_content"].exec("UPDATE_CONTENTS_FIELD", []);
    
	if (form.cate_big_code_a.value == "") {
		alert("상품분류를 선택하세요.");
		return false;
	} else if (form.gs_name.value == "") {
		alert("상품이름을 입력하세요.");
		form.gs_name.focus();
		return false;
	}else if (checked_color_items == 0) {
		alert("적어도 하나의 컬러옵션을 선택하셔야 합니다.")
		return false;
	} else if (checked_size_items == 0) {
		alert("적어도 하나의 사이즈옵션을 선택하셔야 합니다.")
		return false;
	} else if (form.gs_org_price.value == "") {
		alert("판매가를 입력하세요.");
		form.gs_org_price.focus();
		return false;
	} else if (form.gs_sale_price.value == "") {
		alert("할인가를 입력하세요.");
		form.gs_sale_price.focus();
		return false;
	} else if (form.gs_sale_chk.value == "") {
		alert("할인여부를 선택하세요.");
		return false;
	} else if (form.gs_display_chk.value == "") {
		alert("진열여부를 선택하세요.");
		return false;
	} else if (checked_image == 0){
     	alert("이미지 파일을 선택하세요.");
     	return false;
	}else if (checked_image2 == 0){
     	alert("상세이미지 파일을 선택하세요.");
     	return false;
	} else if (document.getElementById("gs_content").value == "") {
		alert("상품설명을 입력하세요.");
		form.gs_content.focus();
		return false;
	} 
    

}

function SelectValue(selectvalue) {
	var sel_id = document.getElementById('s_id');
	sel_id.value = selectvalue;
}

/* function onlyNumber() {
	if ((event.keyCode<48)||(event.keyCode>57)){
		event.returnValue = false;
		alert("숫자만 입력하세요");
	}else{
		event.returnValue = true;
	}	
}


function checkInputNumber() {
	var txt = number.keyCode;
  
  	if(!(txt >= 48 && txt <= 57)) {
   		number.returnValue = false;
   		alert("숫자만 입력하세요");
  	}else{
   		number.returnValue = true;
  	}
}
 
function checkNumber() {
	var objEv = event.srcElement;
	var numPattern = /([^0-9])/;
	var numPattern = objEv.value.match(numPattern);
	if (numPattern != null) {
		alert("숫자만 입력하세요");
		objEv.value = "";
		objEv.focus();
		return false;
	}
} */


</script>

<script type="text/javascript" src="../../se2/js/HuskyEZCreator.js" charset="utf-8"></script>

<!-- 상단제목 -->
<table width="900" align=center cellpadding=0 cellspacing=0>
	<tr>
		<td>
			<div
				style="border:1px solid #ddd; height:34px; background:url(${WEB_ROOT }/img/bbs/title_bg.gif) repeat-x;">
				<div style="font-weight: bold; font-size: 14px; margin: 7px 0 0 10px;" align="center">
					::&nbsp;&nbsp;상품 관리&nbsp;&nbsp;::</div>
			</div>
		</td>
	</tr>
</table>
<p>


<form action="/goodsWrite.do" method="post" name="goods" enctype="multipart/form-data" onSubmit="return validate(this)">
<table width="900" border="1" align="center" bordercolor="#f0f0f0">
		<tr >
			<td width="100" align="center">분류</td>
			<td>
			<select name="cate_big_code" onChange="SelectValue(this.value)">
			<%
				GoodsCategoryModel gcatem = new GoodsCategoryModel();
				for (int i = 0; i < gcatem.getRowCount(); i++) {
					//System.out.println(gcatem.getValueAt(i, 0));
					//System.out.println(gcatem.getValueAt(i, 1));
			%>
				<option value="<%=gcatem.getValueAt(i, 0)%>"><%=gcatem.getValueAt(i, 1)%></option>
			<%
				}
			%>
			</select>
					<input type="text" id="s_id" name="cate_big_code_a" readonly="readonly" value="<%=gcatem.getValueAt(0, 0)%>"/>

					</td>
		</tr>
		<tr>
			<td align="center"><font color="red">상품코드</font></td>
			<td>
			<%
				Calendar cal = Calendar.getInstance(); // 현재 날짜 및 시간 정보를 갖고 있는 Calendar클래스의 인스턴스를 생성
				String strCalendar;
				String strCalendar1;
				int year, mon, day, ho, mi, se;
				year = cal.get(Calendar.YEAR);
				mon = cal.get(Calendar.MONTH) + 1;
				day = cal.get(Calendar.DAY_OF_MONTH);
				ho = cal.get(Calendar.HOUR_OF_DAY);
				mi = cal.get(Calendar.MINUTE);
				se = cal.get(Calendar.SECOND);
				strCalendar = String.valueOf(year) + String.valueOf(mon)
						+ String.valueOf(day);
				strCalendar1 = String.valueOf(year) + String.valueOf(mon)
						+ String.valueOf(day) + String.valueOf(ho)
						+ String.valueOf(mi) + String.valueOf(se);

				String middle_code = String.valueOf(gs_middle_code);
				char[] charArray = middle_code.toCharArray();
				StringBuffer buff = new StringBuffer();

				int num = 4 - middle_code.length();
				int j = 0;

				for (int i = 0; i < 4; i++) {
					if (i < num) {

						buff.append("0");
					} else if (i >= num) {

						buff.append(charArray[j]);
						j++;
					}
					//System.out.println(buff.toString());
				}
				String time = new Timestamp(System.currentTimeMillis()).toString();
				time = time.substring(0,10);
				
			%>

			
		<input type="text" name="gs_middle_code" size="40" readonly="readonly" id="gmc" value="G<%=buff.toString()%>" />&nbsp;&nbsp;(자동으로 코드가 생성 됩니다.)</td>
		</tr>
		<tr>
			<td align="center">상품이름</td>
			<td><input type="text" name="gs_name" size="40" />&nbsp;&nbsp;(100자 안으로 작성)</td>
		</tr>
		<tr>
			<td align="center">컬러옵션</td>
			<td>	

				<%
					for (int i = 0; i < optionColor.length; i++) {

				%>
				<input type="checkbox" name="color_code" onclick="checkbox(this.checked)" value="<%=optionColor[i]%>"><%=optionColor[i]%>
				<%
					}
				%>
				&nbsp;&nbsp;(색상을 선택해주세요)
			</td>
		</tr>
		<tr>
			<td align="center">사이즈옵션</td>
			<td>
	
				<%
					for (int i = 0; i < optionSize.length; i++) {

				%>
				<input type="checkbox" name="size_code" value="<%=optionSize[i]%>"><%=optionSize[i]%>
				<%
					}
				%>
				&nbsp;&nbsp;(사이즈를 선택해주세요)
			</td>
		</tr>
		<tr>
			<td align="center"><font color="red">판매가</font></td>
			<td>
			<input type="text" name="gs_org_price"  maxlength="8" size="12" style="ime-mode:disabled;"
					onKeyPress="if(event.keyCode==13){ event.returnValue=false; } 
  										else if((event.keyCode<48)||(event.keyCode>57)){ 
    									alert('숫자만 넣어주세요'); 
    									event.returnValue=false; 
  										}"
					onKeyDown="if(event.keyCode==229){ 
    									alert('숫자만 넣어주세요(한글)'); 
    									this.value='';
    								    event.returnValue=false; 
    								    }"
			/> 
			
			<%--<input type="text" name="gs_org_price" maxlength="8" size="12" onkeydown="if(event.keyCode<48 || event.keyCode>57)event.returnValue = false;" style="ime-mode:disabled">--%>
			<%--<input type="text" name="gs_org_price" maxlength="8" size="12" style="ime-mode:disabled;"
             onPropertyChange="checkNumber()" />--%>원&nbsp;&nbsp; (원가격을 입력해주세요)</td>
		</tr>
		<tr>
			<td align="center"><font color="red">할인가</font></td>
			<td>
			<input type="text" name="gs_sale_price"  maxlength="8" size="12" style="ime-mode:disabled;"
					onKeyPress="if(event.keyCode==13){ event.returnValue=false; } 
  										else if((event.keyCode<48)||(event.keyCode>57)){ 
    									alert('숫자만 넣어주세요'); 
    									event.returnValue=false; 
  										}"
					onKeyDown="if(event.keyCode==229){ 
    									alert('숫자만 넣어주세요(한글)'); 
    									this.value='';
    								    event.returnValue=false; 
    								    }"
			/> 
			
			<%--<input type="text" name="gs_sale_price" maxlength="8" size="12" style="ime-mode:disabled;" onPropertyChange="checkNumber()" />--%>원&nbsp;&nbsp; (할인가격을 입력해주세요)</td>
		</tr>
		<tr>
			<td align="center">할인유무</td>
			<td><input type = "radio" name = "gs_sale_chk" value="N" checked="checked">판매가&nbsp;
					<input type = "radio" name = "gs_sale_chk" value="Y">할인가&nbsp;&nbsp; (할인 판매 유무를 설정합니다.)</td>
		</tr>
		<tr>
			<td align="center">진열여부</td>
			<td><input type = "radio" name = "gs_display_chk" value="Y" checked="checked">진열중&nbsp;
					<input type = "radio" name = "gs_display_chk" value="N">준비중&nbsp;&nbsp; (제품 전시 여부를 설정합니다.)</td>
		</tr>
		 <tr>
			<td align="center">등록일</td>
			<td><input type="text" name="gs_reg_date" size="30" readonly="readonly" value="<%=time%>"/></td>
		</tr>
		<tr>
			<td align="center">이미지</td>
			<td><input type="file" name="gs_img" size="50" />&nbsp;&nbsp;[권장 사이즈 400 x 400 ] </td>
		</tr>
		<tr>
			<td align="center">상세이미지</td>
			<td><input type="file" name="gs_img2" size="50" />&nbsp;&nbsp;[권장 사이즈 900 x 500 ] </td>
		</tr>
		<tr>
			<td align="center">상품설명</td>
			<td><textarea name="gs_content" id="gs_content" rows="20" cols="145"></textarea></td>
		</tr>
		<tr>
			<td colspan="2" align="center">
			<input type="submit" value="등록" /> 
			<%--<input type="submit" value="등록" onclick="javascript:validate()" />--%>
			<input type="button" value="취소" onclick="javascript:location.reload()" /></td>
		</tr>
</table>
</form>

<script type="text/javascript">

var oEditors = [];

nhn.husky.EZCreator.createInIFrame({

    oAppRef: oEditors,

    elPlaceHolder: "gs_content",

    sSkinURI: "../../se2/SmartEditor2Skin.html",

    fCreator: "createSEditor2"

});

</script>

<%@ include file="/Dmyna/admin/tail.jsp" %>
